import Router, { RouterContext } from 'koa-router'

import { TokenValidator } from '@app/validator'
import { verifyToken } from '@core/util'
import { api } from '@core/decorator'

@api.controller('/v1/token')
class TokenController {
  /**
   * token校验
   * @param token {String} 登录令牌
   * @returns token解码信息
   */
  @api.post('/verify')
  async decryptToken(ctx: RouterContext) {
    const validator = await new TokenValidator().validate(ctx)
    const token = validator.get('body.token')
    const decode = verifyToken(token)
    throw new global.errs.Success(decode)
  }
}
